/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

package com.huawei.saashousekeeper.properties;

import com.huawei.saashousekeeper.dbpool.PoolConfig;

import lombok.Data;
import lombok.experimental.Accessors;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
 * 连接属性
 *
 * @author lWX1156935
 * @since 2022/4/22
 */
@Data
@Accessors(chain = true)
public class DataSourceProperty extends PoolConfig {

    /**
     * 名称
     */
    private String sourceName;

    /**
     * 连接池名称
     */
    private String poolName;

    /**
     * JDBC连接参数 driver
     */
    private String driverClassName;

    /**
     * JDBC连接参数 url 地址
     */
    private String url;

    /**
     * JDBC连接参数 用户名
     */
    private String username;

    /**
     * JDBC连接参数 密码
     */
    private String password;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        DataSourceProperty that = (DataSourceProperty) o;

        return new EqualsBuilder().appendSuper(super.equals(o))
            .append(sourceName, that.sourceName)
            .append(poolName, that.poolName)
            .append(driverClassName, that.driverClassName)
            .append(url, that.url)
            .append(username, that.username)
            .append(password, that.password)
            .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37).appendSuper(super.hashCode())
            .append(sourceName)
            .append(poolName)
            .append(driverClassName)
            .append(url)
            .append(username)
            .append(password)
            .toHashCode();
    }
}
